ggvis: both static and interactive graphics, interactive is very much a work in progress (Wickham)plotly: has come a long way in the last 12 months, part of Carson Sievert’s PhD thesis research. The beauty is that is builds directly onto ggplot2animint: Hasn’t progressed much in the last year, needs special copy of ggplot2 (Hocking, et al)htmlwidgets: has progressed a lot in 12 months, providing the base for other packages, e.g. plotly (Chang)rCharts, rbokeh, gridSVG, epivizrBuilt on the javascript library vega
data("economics", package = "ggplot2")
ggvis(economics, x=~date, y=~psavert)
economics %>%
ggvis(~date, ~psavert) %>%
layer_points() %>%
layer_smooths()
The coolest thing about ggvis is that plot parameters don’t need to be static: they can be interactive
input_text(): text boxinput_slider(): numeric sliderinput_select(): dropdown boxinput_checkbox(): checkboxeconomics %>%
ggvis(~date, ~psavert) %>%
layer_points() %>%
layer_smooths(
span = input_slider(0.2, 1)
)
stop icon on the plot panelThe values provided for the slider (0.2, 1) look like they are not ideal. Change slider bounds so that they are more appropriate for this data.
economics %>%
ggvis(~date, ~psavert) %>%
layer_points(opacity := 0.5) %>%
layer_smooths(
stroke := "red",
span = input_slider(0.1, 0.8)
)
all_values <- function(x) {
if (is.null(x)) return(NULL)
paste0(names(x), ": ", format(x), collapse = "<br />")
}
economics %>%
ggvis(~unemploy, ~psavert) %>%
layer_points() %>%
add_tooltip(all_values, "hover")
model_type <- input_checkbox(label = "Use loess curve",
map = function(val) if(val) "loess" else "lm")
economics %>%
ggvis(~date, ~psavert) %>%
layer_points() %>%
layer_model_predictions(model = model_type)
library(MASS) # for rlm
model_type <- input_radiobuttons(
choices = c("LOESS" = "loess", "LM" = "lm", "Robust" = "rlm"),
selected = "loess",
label = "Model type")
economics %>%
ggvis(~date, ~psavert) %>%
layer_points(opacity := 0.5) %>%
layer_model_predictions(model = model_type, stroke := "red")
The plotly package in R builds on the ggplot2 package, adding interactive elements to these plots. It translates plots to javascript.
plot_ly(economics, x = date, y = unemploy / pop)
ggplot(data=economics, aes(x = date, y = unemploy / pop)) +
geom_point() + geom_line()
ggplotly()
library(GGally)
p <- ggpairs(economics[,3:6])
ggplotly(p)
data(canada.cities, package = "maps")
viz <- ggplot(canada.cities, aes(long, lat)) +
borders(regions = "canada") +
coord_equal() +
geom_point(aes(text = name, size = pop), colour = "red", alpha = 1/2)
ggplotly(viz)
library(edgeR)
coty <- read_delim("./data/GSE61857_Cotyledon_normalized.txt.gz",
delim="\t", col_types="cddddddddd",
col_names=c("ID", "C_S1_R1", "C_S1_R2", "C_S1_R3",
"C_S2_R1", "C_S2_R2", "C_S2_R3", "C_S3_R1", "C_S3_R2", "C_S3_R3"),
skip=1)
coty <- as.data.frame(coty)
d <- DGEList(counts = coty[,2:7],
group = c(rep("S1", 3), rep("S2", 3)),
genes = coty[,1])
d <- calcNormFactors(d)
d <- estimateCommonDisp(d)
d <- estimateTagwiseDisp(d)
d <- estimateTrendedDisp(d)
de <- exactTest(d, pair=c("S1", "S2"), dispersion = "trended")
sig.tab <- de$table
sig.tab$genes <- coty$ID
sig.tab <- dplyr::filter(sig.tab, PValue < 0.01)
sig.tab <- merge(sig.tab, coty[,1:7], by.x="genes", by.y="ID")
ggscatmat(sig.tab, columns=5:10, alpha=0.1)
p <- ggplot(sig.tab, aes(x=C_S1_R2, y=C_S2_R1, label=genes)) +
geom_point(alpha=0.1)
ggplotly(p)
With a large data set it can be slow!
library(eechidna)
launchApp(
age = c("Age20_24", "Age85plus"),
religion = c("Christianity", "Catholic", "NoReligion"),
other = c("Unemployed", "Population", "MedianIncome")
)
plotly github page examples and play with some of the examples.